package com.kly.user.utils;

import com.alibaba.excel.util.StringUtils;
import org.apache.logging.log4j.util.Strings;

public class ImagePrefixUtils {

    private static String photoPrefix = "https://storage.googleapis.com/meboo-online-b68e7.appspot.com";

    private static String touchuPrefix = "https://storage.googleapis.com/touchu-98bec.appspot.com";

    private static String ppPrefix = "https://storage.googleapis.com/passionpulse-6112f.appspot.com";

    /**
     * 默认返回meboo 图片地址
     */
    public static String getFullImageUrl(String imageUrl) {
        if (StringUtils.isEmpty(imageUrl)) {
            return Strings.EMPTY;
        }

        if (imageUrl.contains("http") || imageUrl.contains("https")) {
            return imageUrl;
        }

        if (imageUrl.contains("/tounchu")) {
            return touchuPrefix + imageUrl;
        }

        if (imageUrl.contains("/passionpulse")) {
            return ppPrefix + imageUrl;
        }

        if (imageUrl.contains("/images") || imageUrl.contains("/icons")) {
            return photoPrefix + imageUrl;
        }
        return photoPrefix + imageUrl;
    }

    public static String removePrefix(String url) {
        if (StringUtils.isBlank(url)) {
            return null;
        }
        if (url.contains("https") || url.contains("http")) {
            if (url.contains("touchu")) {
                return url.replaceAll(touchuPrefix, "");
            }
            else if (url.contains("passionpulse")) {
                return url.replaceAll(ppPrefix, "");
            }
            else {
                return url.replaceAll(photoPrefix, "");
            }

        }
        return url;
    }
}
